package com.qding.park.manager.app.queue;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.qding.park.common.core.constant.CacheKeyThree;
import com.qding.park.common.core.exceptions.IExceptionHandle;
import com.qding.park.common.core.redis.JedisClient;
import com.qding.park.common.core.redis.SerializeUtils;
import com.qding.park.manager.app.queue.handle.MonthPayedHandle;
import com.qding.park.manager.app.queue.handle.TempPayedHandle;
import com.qding.park.manager.app.queue.handle.TeneratPayedHandle;
import com.qding.park.manager.app.queue.util.SpringContextUtil;
import com.qding.park.manager.pojo.queue.QueueMsg;
import com.qding.park.manager.pojo.queue.QueueTypeEnum;

public class QueueReportRunTask implements Runnable {

	private static final Log _log = LogFactory.getLog(QueueReportRunTask.class);
	/**
	 * @Field @jedisClient : TODO(jedis Client)
	 */
	private JedisClient jedisClient;

	private IExceptionHandle exceptionHandle;

	public QueueReportRunTask(JedisClient jedisClient, IExceptionHandle exceptionHandle) {
		this.jedisClient = jedisClient;
		this.exceptionHandle = exceptionHandle;
	}

	@Override
	public void run() {
		String key = CacheKeyThree.QUEUE_REPORT;
		while (true) {

			try {
				String value = jedisClient.rpop(key);

				if (StringUtils.isBlank(value)) {
					// 队列里面没有值
					Thread.sleep(1000 * 5);
				} else {
					QueueMsg msg = SerializeUtils.unSerialize(value, QueueMsg.class);
					
					HandleWrap.handle(msg);
				}
			} catch (Exception e) {
				exceptionHandle.handle(e);
			}

		}

	}

}
